<template>
  <div id="class">
    <div class="bgc">
      <van-row>
        <van-col span="24">
          <van-nav-bar :title="title" left-arrow @click-left="onClickLeft" />
        </van-col>
        <van-col span="24">
          <van-tabs v-model="activeName" @rendered="rendered" animated>
            <van-tab v-for="item in TabDataList.currentSubCategory" :title="item.name" :key="item.id">
              <van-col span="24" class="centenr-p">
                <p>{{ item.name }}</p>
                <p>{{ item.desc }}</p>
              </van-col>
              <van-col class="centenr" span="24">
                <van-col span="12" v-for="(item, index) in ClassGoodsList" :key="index">
                  <div>
                    <img :src="item.picUrl" alt="" />
                    <p class="van-ellipsis">{{ item.name }}</p>
                    <p>￥{{ item.counterPrice }}</p>
                  </div>
                </van-col>
              </van-col>
            </van-tab>
          </van-tabs>
        </van-col>
      </van-row>
    </div>
  </div>
</template>
<script>
export default {
  name,
  data() {
    /*  */
    return {
      title: '',
      activeName: 0,
      // 标签栏的数据
      TabDataList: {}, //tab栏内容
      ClassGoodsList: {} // 分类商品的内容
    }
  },
  // 计算属性
  // 当vuex里面的值改变就会实时更新
  mounted() {
    this.activeName = this.$route.query.index
    this.onGetTabList()
  },
  methods: {
    onClickLeft() {
      this.$router.back()
    },
    // 请求当前 栏 下对应的内容
    rendered(index) {
      let data = {
        categoryId: this.TabDataList.currentSubCategory[index].id
      }
      this.$get('goods/list', data).then(result => {
        console.log(result)
        this.ClassGoodsList = result.data.data.list
      })
    },
    // 获取导航栏的内容。
    onGetTabList() {
      this.$get('catalog/index').then(result => {
        console.log(result)
        this.TabDataList = result.data.data
      })
    }
  }
}
</script>
<style lang="less" scoped>
.bgc {
  height: 100vh;
  position: absolute;
  top: 0;
  background-color: #f6f8f7;
}
.centenr-p {
  text-align: center;
  p:nth-child(1) {
    font-size: 0.15rem;
    font-weight: 600;
    margin-top: 0.1rem;
  }
  p:nth-child(2) {
    margin: 0.1rem 0px;
    opacity: 0.5;
  }
}
.centenr {
  .van-col {
    padding: 2px;
    div {
      height: 250px;
      background-color: #fff;
      text-align: center;
      img {
        width: 90%;
      }
      p:nth-child(2) {
        font-size: 0.15rem;
        margin: 0.1rem 0px;
        font-weight: 600;
      }
      p:nth-child(3) {
        color: chocolate;
      }
    }
  }
}
</style>
